#!/bin/bash
# Copyright (c) 2017, The MesaLock Linux Project Contributors
# All rights reserved.
#
# This work is licensed under the terms of the BSD 3-Clause License.
# For a copy, see the LICENSE file.

set -e

workdir="$(pwd)"
builddir="$(pwd)/build"
rootfsdir="$builddir/rootfs"

echo "[+] mesalockrootfs: installing packages"
packages=(filesystem \
          glibc \
          gcc-libs \
          ion-shell \
          uutils-coreutils \
          ripgrep \
          fd-find \
          tzdata \
          xi-core \
          xi-tui \
          uutils-findutils \
          tokei \
          brotli \
          micro \
          mesalock-demo)

rm -rf "$rootfsdir"
mkdir -p "$rootfsdir"

for p in "${packages[@]}"; do
  tar xkfJ "$builddir/out/$p.tar.xz" -C "$rootfsdir"
done

echo "[+] mesalockrootfs: tar and zip rootfs"
tar cfJ "$builddir/rootfs.tar.xz" -C "$rootfsdir" .
